/*
 * CopyAction.java
 *
 * Created on 15 April 2007, 15:02
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package org.cardcopier.ui;

import java.awt.event.ActionEvent;
import java.io.File;
import java.io.IOException;
import java.util.List;
import javax.swing.AbstractAction;
import javax.swing.JFrame;
import org.cardcopier.CardCopierModel;
import org.cardcopier.file.FileCopier;
import org.cardcopier.file.FileState;
import org.cardcopier.file.FileUtils;

/**
 *
 * @author Mark
 */
public class CopyAction extends AbstractAction {
    
    private final CardCopierModel cardCopierModel;
    private final FileDetailsTable fileDetailsTable;
    private final JFrame copyActionFrame;
    
    public CopyAction(CardCopierModel cardCopierModel, FileDetailsTable fileDetailsTable, JFrame copyActionFrame) {
        super("Copy");
        this.cardCopierModel = cardCopierModel;
        this.fileDetailsTable = fileDetailsTable;
        this.copyActionFrame = copyActionFrame;
    }

    public void actionPerformed(ActionEvent e) {
        List<FileState> filesToCopy = fileDetailsTable.getSelectedFiles();
        boolean moveFiles = cardCopierModel.getDeleteSourceFileAfterCopy();
        final FileCopierProgressDialog dialog =
                new FileCopierProgressDialog(copyActionFrame, filesToCopy, moveFiles);
        dialog.startCopy();
        dialog.setVisible(true);
        if (moveFiles) {
            cardCopierModel.notifyOfSourceLocationChange();
        }
        cardCopierModel.notifyOfDestinationChange();
    }
    
}
